<script setup>
import InputEditer from '../components/InputEditer.vue'
import InputEditerArr from '../components/InputEditerArr.vue'
import { ref, onMounted, nextTick } from 'vue'
import { dataProcessing_v2x } from '../js/dataPro_v2x.js'
import { dataProcessing_v2x2 } from '../js/dataPro_v2x2.js'
import { _getData } from '/src/api/parameterConfiguration/getData.js'
import { mainStore } from '/src/store/mainStore.js'

const store = mainStore()
let data = ref(null)

const handleTitleClick = async (value) => {
  if (value == store.eventTitle) return
  store.eventTitle = value
  // 清空当前的所有东西
  store.saveAllData = []
  if (store.eventTitle == 1) {
    store.cutArgPage = 'v2x-app'
    getList()
  }

  if (store.eventTitle == 2) {
    store.cutArgPage = 'v2x-prostack'
    getList2()
  }
}
const getList = async () => {
  const res = await _getData(store.cutArgPage)

  if (res?.data?.code != 200) return ElMessage.error('获取数据失败')
  data.value = dataProcessing_v2x(res.data.data)
}

const getList2 = async () => {
  const res = await _getData(store.cutArgPage)

  if (res?.data?.code != 200) return ElMessage.error('获取数据失败')
  data.value = dataProcessing_v2x2(res.data.data)
}

let height = ref('0px')
onMounted(() => {
  nextTick(() => {
    store.eventTitle == 1 ? getList() : getList2()
    const h = document.querySelector('.v2x-container').getBoundingClientRect().height
    height.value = h - 42 + 'px'
  })
})
</script>

<template>
  <div class="v2x-container">
    <!-- 主要的参数 -->
    <div class="title">
      <div @click="handleTitleClick(1)" :class="store.eventTitle == 1 ? 'selecdCss' : ''">v2x</div>
      <div @click="handleTitleClick(2)" :class="store.eventTitle == 2 ? 'selecdCss' : ''">协议栈配置</div>
    </div>

    <!-- 带title的 输入  -->
    <div class="show-main" :style="{ maxHeight: height }" v-if="store.eventTitle == 1">
      <div v-for="item in data?.data_main">
        <p class="title2">{{ item.title }}</p>

        <!-- 主体输入 -->
        <div class="input-main">
          <div class="input-item" v-for="itn in item.data">
            <InputEditer v-if="!itn.arr" :data="itn" :width="220" />
            <InputEditerArr v-else :data="itn" :width="220" />
          </div>
        </div>
      </div>
    </div>

    <div class="show-main show-main2" :style="{ maxHeight: height }" v-if="store.eventTitle == 2">
      <div v-for="item in data?.data_main2">
        <p class="title2">{{ item.title }}</p>

        <!-- 主体输入 -->
        <div class="input-main">
          <div class="input-item" v-for="itn in item.data">
            <InputEditer :data="itn" :width="280" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.v2x-container {
  width: 100%;
  height: 100%;
  font-size: 14px;
  padding: 0 6px 0 20px;
  display: flex;
  flex-direction: column;
}

.title {
  width: 100%;
  margin-top: 10px;
  display: flex;
  align-items: center;
  > div {
    width: 80px;
    margin-right: 10px;
    height: 22px;
    background-color: #ccc;
    line-height: 22px;
    border-radius: 2px;
    cursor: pointer;
    text-align: center;
  }
}

.title2 {
  color: blue;
}

.selecdCss {
  color: white;
  background-color: #4095e5 !important;
}

.show-main {
  width: 100%;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  overflow-y: auto;
  margin-top: 10px;

  .input-main {
    width: 100%;
    min-width: 500px;
    margin-top: 10px;
    padding: 0 20px;

    overflow-y: auto;
    .input-item {
      // width: 100%;
      margin-bottom: 16px;
    }
  }
  .title {
    color: blue;
    margin-bottom: 10px;
    padding-left: 40px;
  }
}

.show-main2 {
  margin-top: 20px;
}

.item {
  display: flex;
  align-items: center;
}
</style>
